#coding:utf-8
__author__ = 'hl'
import urllib
import urllib2

#使用http提交数据
class SubmitData:

    #datas是保存元祖列表类型参数，并且元祖的第一个元素是传递的参数名称字符串如：“name”,或者是字典类型第一个Key就表示参数名称
    def SubmitDataByPost(self,url,datas):
        # try:
        #     request = urllib2.Request(url)
        #     datas = urllib.urlencode(datas)
        #     return urllib2.urlopen(request,datas)
        # except:
        #     print 'class: SubmitData' \
        #           'method: SubmitDataByPost'\
        #           'Error Message: the type of agrs passed is inavailable '
        #     return None
        request = urllib2.Request(url)
        datas = urllib.urlencode(datas)
        return urllib2.urlopen(request,datas)

    def SubmitDataByGet(self,url,datas):
        try:
            url += '?'+urllib.urlencode(datas)
            print url
            request = urllib2.Request(url)
            return urllib2.urlopen(request)
        except:
            print 'class: SubmitData' \
                  'method: SubmitDataByPost'\
                  'Error Message: the type of agrs passed is inavailable '
            return  None



